import datetime
import db
import KBEDebug as log
import KBEngine
import time


ton = [0, 0.6, 1.2, 3, 9, 20, 50]


class LobbyPayment:
    def __init__(self, table_name):
        self.table_name = table_name
        self.tb = db.DBTable(table_name)
        # 玩家playerId
        self.tb.setFiled('playerId', db.UINT32())
        # 支付时间
        self.tb.setFiled('paytime', db.UINT32())
        # 支付金额
        self.tb.setFiled('ton', db.FLOAT())

    def createTable(self, success_callback):
        self.tb.exec(success_callback)


class ILobbyPayment:
    def __init__(self):
        self.tb_LobbyPayment = LobbyPayment('lobby_payment')
        self.tb_LobbyPayment.createTable(None)

    def addPaymentRecord(self, player_id, prop_id):
        log.INFO_MSG(f'addPaymentRecord: {player_id} {prop_id}')
        info = {
            'playerId': player_id,
            'paytime': int(time.time()),
            'ton': ton[prop_id]
        }
        self.tb_LobbyPayment.tb.addLine(info)
